package com.etoak.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class OrderQueueConfig {

    public static final String EXCHANGE = "amqp.order";

    public static final String QUEUE = "order.quque";

    public static final String KEY = "order.key";

    @Bean
    public CustomExchange customExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(EXCHANGE,
                "x-delayed-message",
                true,
                false,
                args);
    }

    @Bean
    public Queue queue(){
        return new Queue(QUEUE);
    }

    @Bean
    public Binding binding(Queue queue,CustomExchange customExchange){
        return BindingBuilder.bind(queue).to(customExchange).with(KEY).noargs();
    }

}
